package BryantChad.LunchTimeScoreCard;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class CreateNewGameActivity  extends ListActivity {
	private Game newGame_;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newgame);

        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1));
        
        Intent intent = getIntent();
        newGame_ = (Game)intent.getSerializableExtra("game");
        
        final Button btnAddPlayer = (Button) findViewById(R.id.btnAddPlayer);
        btnAddPlayer.setOnClickListener(btnAddPlayerClick);
        
        final Button btnStartGame = (Button) findViewById(R.id.btnStartGame);
        btnStartGame.setOnClickListener(btnStartGameClick);
    }
    
    private View.OnClickListener btnAddPlayerClick = new View.OnClickListener() {
    	@Override
		public void onClick(View v)  {
            // Perform action on clicks
    		final EditText txtPlayer = (EditText) findViewById(R.id.txtAddPlayer);
    		final ListView lstPlayers = getListView();
    		final ArrayAdapter<String> players = (ArrayAdapter<String>)lstPlayers.getAdapter();
    		String playerName = txtPlayer.getText().toString(); 
    		
    		players.add(playerName);
    		
    		Player newPlayer = new Player(playerName, 0);
	    	newGame_.Players.add(newPlayer);
    		txtPlayer.setText("");
        }
	};
	
	private View.OnClickListener btnStartGameClick = new View.OnClickListener() {
    	@Override
		public void onClick(View v)  {
            // Perform action on clicks
    		Intent myIntent = new Intent(CreateNewGameActivity.this, KeepScoreActivity.class);
    		
    		myIntent.putExtra("game", newGame_);
    		
    		CreateNewGameActivity.this.startActivity(myIntent);
        }
	};
}
